﻿@using System.Activities.Statements
@model contos.ViewModel.InstructorIndexData
<link href="~/Content/newStyle.css" rel="stylesheet" />
@{
    ViewBag.Title = "教师";
}

<h2>Index</h2>

<p>
    @Html.ActionLink("Create New", "Create")
</p>
<table class="gridtable">
    <tr>
        <th>
            Last Name
        </th>
        <th>
            First 
        </th>
        <th>
            Hire Date
        </th>
        <th>
            Office
        </th>
        <th>
            Courses
        </th>
        <th></th>
    </tr>

    @foreach (var item in Model.Instructors)
    {
        string selectedRow = "";
        if (item.InstructorID==ViewBag.InstructorID)
        {
            selectedRow = "selectedrow";
        }
        <tr class="@selectedRow" valign="top">
            <td>
                @Html.DisplayFor(modelItem => item.LastName)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.FirstMidName)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.HireDate)
            </td>
            <td>
                @if (item.OfficeAssignment!= null)
                {
                    @item.OfficeAssignment.Location
                }
            </td>
            <td>
                @{
        foreach (var course in item.Courses)
        {
            @course.CourseID @:  @course.Title <br />
        }
                }
            </td>
            <td>
                @Html.ActionLink("Select","Index",new {id=item.InstructorID})
                @Html.ActionLink("Edit", "Edit", new { id=item.InstructorID }) |
                @Html.ActionLink("Details", "Details", new { id=item.InstructorID }) |
                @Html.ActionLink("Delete", "Delete", new { id=item.InstructorID })
            </td>
        </tr>
    }

</table>
@if (Model.Courses != null)
{
    <h3>选择老师的课程</h3>
    <table class="gridtable">
        <tr>
            <th></th>
            <th>ID</th>
            <th>题目</th>
            <th>院系</th>
        </tr>
        
        @foreach (var item in Model.Courses)
        {
            string selectedRow = "";
            if (item.CourseID == ViewBag.CourseId)
            {
                selectedRow = "selectedRow";
            }
            <tr class="@selectedRow">
                <td>  @Html.ActionLink("select", "Index", new {courseId = item.CourseID})  </td>
                <td>
                    @item.CourseID
                </td>
                <td>
                    @item.Title
                </td>
                <td>
                    @item.Department.Name
                </td>
            </tr>
        }

    </table>
}  
@if (Model.Enrollments != null)
     {
         <h3>选择该课程的学生</h3>
         <table class="gridtable">
             <tr>
                 <th>姓名</th>
                 <th>成绩</th>
             </tr>
             @foreach (var item in Model.Enrollments)
             {
                 <tr>
                     <td>
                         @item.Student.LastName+@item.Student.FirstMidName
                     </td>
                     <td>
                         @Html.DisplayFor(s=>item.Grade)
                     </td>
                 </tr>
             }
             
             

         </table>
     }

